package com.huifaapp.mall.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.GoodstoboActivity;
import com.huifaapp.mall.bean.GoodsReceivedBean;

import java.util.List;

/**
 * Created by mac on 2017/12/8.
 */

public class GoodsReceivedAdapter extends RecyclerView.Adapter<GoodsReceivedAdapter.MyViewHolder> {
    private Context context;
    private MyViewHolder myViewHolder;
    private List<GoodsReceivedBean.OrderListBean> list;

    public GoodsReceivedAdapter(Context context, List<GoodsReceivedBean.OrderListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.goodsrece_item,null);
        myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        if (itemClickListener != null) {
            myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    itemClickListener.OnItemClickListener(myViewHolder.itemView, myViewHolder.getLayoutPosition());
                }
            });
            myViewHolder.bt_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    itemClickListener.Btconfirm(myViewHolder.itemView, myViewHolder.getLayoutPosition());
                }
            });
        }
        final GoodsReceivedBean.OrderListBean orderListBean = list.get(position);   //获取当前条目的数据
        List<GoodsReceivedBean.OrderListBean.DataBean> data = orderListBean.getData();   //获取到内层的数据集合
        GoodsReceivedAdaptertwo goodsReceivedAdaptertwo = new GoodsReceivedAdaptertwo(context,data);//创建内层的适配器

        goodsReceivedAdaptertwo.setOnItemClickListener(new PendpayAdaptertwo.OnItemClickListenertwo() {
            @Override
            public void OnItem(View view, int position) {
                Intent intent = new Intent(context, GoodstoboActivity.class);
                intent.putExtra("orderNo",orderListBean.getOrderNo());
                context.startActivity(intent);
            }
        });



        holder.deliveryrecy.setAdapter(goodsReceivedAdaptertwo);   //绑定内层的适配器
        holder.sum_count.setText("共计" + orderListBean.getTotalcount() + "件商品");   //商品的总个数
        holder.sum_money.setText("合计: ¥" + orderListBean.getTotalprice());   //商品的总价
        holder.yunfei.setText("(含运费¥ " + orderListBean.getExpressFee() + ")");   //商品的运费
        holder.dd_num.setText(orderListBean.getOrderNo()+"");
    }

    @Override
    public int getItemCount() {
        return list.size();

    }
//@Override
//    public int getItemCount(){
//        return list.size();
//    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

//        ImageView imageView;
//        TextView shop_name;
//        TextView shop_xjprice;
//        TextView shop_yjprice;
//        TextView shop_num;
//        TextView shop_color;
//        TextView shop_size;

        RecyclerView deliveryrecy;
        TextView yunfei, sum_money, sum_count,dd_num;
        Button bt_confirm;
        Button bt_xqym;

        public MyViewHolder(View itemView) {
            super(itemView);

            deliveryrecy = (RecyclerView) itemView.findViewById(R.id.goodsrecy_recy);
            deliveryrecy.setLayoutManager(new LinearLayoutManager(context));
            yunfei = (TextView) itemView.findViewById(R.id.goodsrece_hyf);
            sum_money = (TextView) itemView.findViewById(R.id.goodsrece_hj);
            sum_count = (TextView) itemView.findViewById(R.id.goodsrece_gj);
            bt_confirm = (Button) itemView.findViewById(R.id.goodsrece_confirm);
            dd_num = (TextView) itemView.findViewById(R.id.goodsrece_ddnum);



        }
    }

    public interface MyOnItemClickListener {
        void OnItemClickListener(View view, int position);
        void Btconfirm(View view, int position);

    }
    private MyOnItemClickListener itemClickListener;

    public void setOnItemClickListener(MyOnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }


}